<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>北京航天公司固定资产管理系统</title>
</head>
<body>

<button class="layui-btn" style="float: left" onclick="buildScrap()">报修申请</button>
<br><br>
<script type="text/html" id="myoperate">
    <button class="layui-btn layui-btn-normal" lay-event="scrap">维修成功</button>
    <button class="layui-btn layui-btn-danger" lay-event="scrapc">报废</button>
</script>
<table id="myTable" lay-filter="myFilter"></table>

<script type="text/html" id="myoperate1">
    <a class="layui-table-link" lay-event="detail">查看</a>
</script>
<input type="hidden" id="rankNum" th:value="${session.userInfo.rankNum}">
</body>
</html>
<script type="text/javascript" src="/js/jquery-1.8.2.js"></script>
<script type="text/javascript" src="/layui/layui.all.js"></script>
<link rel="stylesheet" href="/layui/css/layui.css">
<script>
    var table = layui.table;
    table.render({
        elem: '#myTable',//绑定表格的id
        url: "/scrap/scrapFindAll",
        width: 1600,
        height: 350,
        method: 'post',
        autoSort: false,
        toolbar: '#toolbarDemo', //开启头部工具栏
        cols: [[{
            title: '操作',
            align: 'center',//字体居中
            toolbar: '#myoperate1'
        }, {
            field: 'scrap_id',
            title: '报修单号',
            align: 'center',//字体居中
        }, {
            field: 'scrap_state',
            title: '报修状态',
            align: 'center',//字体居
            templet: function (d) {
                if (d.scrap_state == 8) {
                    return '报废'
                } else if (d.scrap_state == 7) {
                    return '维修成功'
                } else if (d.scrap_state == 6) {
                    return '维修中'
                }
            }
        }, {
            field: 'property_id',
            title: '资产编号',
            align: "center",
        }, {
            field: 'property_name',
            title: '资产名称',
            align: "center",
        },{
            field: 'responsible',
            title: '资产责任人',
            align: 'center',//字体居中
            /* templet : '#sexTpl',//绑定代码模板 暂时用不到 男女 * */
        }, {
            field: 'start_scrap_time',
            title: '申请报修时间',
            align: 'center',//字体居中
            /*  sort: true*/
            /* templet : '#sexTpl',//绑定代码模板 暂时用不到 男女 * */
        }, {
            field: 'scrap_operator',
            title: '报修操作人',
            align: 'center',//字体居中
            /* sort: true,*/
        }, {
            field: 'faultname',
            title: '故障类型',
            align: 'center',//字体居中
        }, {
            field: 'scrap_description',
            title: '故障备注',
            align: 'center',//字体居中
        }, {
            title: '操作',
            align: 'center',//字体居中
            width: 200,
            toolbar: '#myoperate'
        },]
        ],
        limits: [3, 5],//每页条数的选择项，默认：[10,20,30,40,50,60,70,80,90]。
        limit: 3,//每页显示的条数（默认：10）。值务必对应 limits 参数的选项。
        page: true,//是否开启分页
        request: {
            pageName: 'page',
            limitName: 'limit'
        }
    });


    //监听工具条
    table.on('tool(myFilter)', function (obj) {
        var data = obj.data;
        var scrap_id = data.scrap_id;
        var property_id=data.property_id;
        var property_name=data.property_name;
        var responsible=data.responsible;
        //console.log(scrap_id);
        console.log(property_name)
        var rankNum = $("#rankNum").val()

        /*获取到指定行的ID*/
        if (obj.event === 'termination') {

        } else if (obj.event === 'detail') {//查看申请单详细
            window.location.href = "/jump/goScrapDetail?scrap_id=" + scrap_id;
        } else if (obj.event === 'scrap') {
            if (rankNum == 2 || rankNum==1) {
                window.location.href = "/jump/gofoster?property_id="+property_id+"&property_name="+property_name+"&responsible="+responsible;

                /*$.get("/scrap/updateScrapState?scrap_state=" + 7 + "&scrap_id=" + scrap_id+"&property_id="+property_id, function (res) {//维修成功
                    if (res.code == 1) {
                        /!*alert("资产维修成功")*!/

                    }
                })*/
            } else {
                alert("您无权操作，谢谢！")
            }
        } else if (obj.event === 'scrapc') {
            if (rankNum == 2  || rankNum==1) {
                $.get("/scrap/updateScrapState?scrap_state=" + 8 + "&scrap_id=" + scrap_id+"&property_id="+property_id, function (res) {//报废（维修失败）
                    if (res.code == 1) {
                        alert("资产报废")
                        window.location.href = "/jump/goScrapIndex"
                    }
                })
            } else {
                alert("您无权操作，谢谢！")
            }
            /*  window.location.href="/scrap/updateScrapState?scrap_state="+8+"&scrap_id="+scrapId;*/

        }
    });

    //跳转申请报废表
    function buildScrap() {
        window.location.href = "/jump/gobuildScrap";
    }


</script>